<?php
defined('IN_TS') or die('Access Denied.');

//发表评论 
if($ts=='addcomment'){
	if (IS_POST) {
		$topicid	= intval($_POST['topicid']);
		$content	= h($_POST['content']);
		//标签
		doAction('add_comment','',$content,'');
		
		if($TS_USER['user'] == ''){
			qiMsg('请登陆后再发表内容^_^','点击登陆','index.php?app=user&ac=login');
		}elseif(empty($content)){
			qiMsg('没有任何内容是不允许你通过滴^_^');
		}else{
			$arrData	= array(
				'topicid'			=> $topicid,
				'userid'			=> $TS_USER['user']['userid'],
				'content'	=> $content,
				'addtime'		=> time(),
			);
			
			$commentid = $DB->insertArr($arrData,'app_group_topics_comments');
			
			//统计评论数
			$count_comment = $DB->once_num_rows("select * from ".dbprefix."app_group_topics_comments where topicid='$topicid'");
			
			//更新帖子最后回应时间和评论数
			$uptime = time();
			
			$DB->query("update ".dbprefix."app_group_topics set uptime='$uptime',count_comment='$count_comment' where topicid='$topicid'");
			
			//积分记录
			$userid = $TS_USER['user']['userid'];
			$DB->query("insert into ".dbprefix."app_user_scores (`userid`,`scorename`,`score`,`addtime`) values ('".$userid."','回帖','20','".time()."')");
			
			$strScore = $DB->once_fetch_assoc("select sum(score) score from ".dbprefix."app_user_scores where userid='".$userid."'");
			
			//更新积分
			$DB->query("update ".dbprefix."app_user_info set `count_score`='".$strScore['score']."' where userid='$userid'");
			
			//发送系统消息(通知楼主有人回复他的帖子啦)
			$strTopic = $DB->once_fetch_assoc("select * from ".dbprefix."app_group_topics where topicid='$topicid'");
			if($strTopic['userid'] != $TS_USER['user']['userid']){
			
				$msg_userid = '0';
				$msg_touserid = $strTopic['userid'];
				$msg_content = '你的帖子：《'.$strTopic['title'].'》新增一条评论，快去看看给个回复吧^_^ <br />'
											.$TS_SITE['base']['site_url'].'index.php?app=group&ac=topic&topicid='.$topicid;
				aac('message',$DB)->sendmsg($msg_userid,$msg_touserid,$msg_content);
				
			}
			header("Location: ".$TS_URL['topic'].$topicid.$TS_URL['suffix']);
		}	
	}
}

switch ($ts) {

	case "new_topic":
		$groupid	= intval($_POST['groupid']);
		
		$title	= t($_POST['title']);
		$content	= h($_POST['content']);
		
		//标签
		doAction('add_topic',$title,$content,'');
		
		$strGroup = $DB->once_fetch_assoc("select * from ".dbprefix."app_group where groupid='$groupid'");
		
		$typeid = intval($_POST['typeid']);
		
		
		$iscomment = $_POST['iscomment'];

		if($TS_USER['user'] == ''){
		
			qiMsg('请登陆后再发表内容^_^','点击登陆','index.php?app=user&ac=login');
			
		}elseif(empty($title)){

			qiMsg('不要这么偷懒嘛，多少请写一点内容哦^_^');
			
		}elseif(empty($content)){

			qiMsg('没有任何内容是不允许你通过滴^_^');
			
		}else{
			
			$uptime = time();
			
			$arrData = array(
				'groupid'				=> $strGroup['groupid'],
				'groupname'			=> $strGroup['groupname'],
				'typeid'	=> $typeid,
				'userid'				=> $TS_USER['user']['userid'],
				'username'			=> $TS_USER['user']['username'],
				'title'				=> $title,
				'content'		=> $content,
				'iscomment'		=> $iscomment,
				'addtime'			=> time(),
				'uptime'	=> $uptime,
			);
			
			//判断是否有图片和附件
			preg_match_all('/\[(photo)=(\d+)\]/is', $content, $isphoto);
			if($isphoto[2]){
				$arrData['isphoto'] = '1';
			}
			//判断附件
			preg_match_all('/\[(attach)=(\d+)\]/is', $content, $isattach);
			if($isattach[2]){
				$arrData['isattach'] = '1';
			}
			
			$topicid = $DB->insertArr($arrData,'app_group_topics');
			
			//统计帖子类型 
			if($typeid != '0'){
				$topicTypeNum = $DB->once_num_rows("select * from ".dbprefix."app_group_topics where typeid='$typeid'");
				$DB->query("update ".dbprefix."app_group_topics_type set `count_topic`='$topicTypeNum' where typeid='$typeid'");
			}
			//处理标签
			aac('tag',$DB)->addTag('topic','topicid',$topicid,$_POST['tag']);
			
			//统计小组下帖子数并更新
			$count_topic = $DB->once_num_rows("select * from ".dbprefix."app_group_topics where groupid='$groupid'");
			
			//统计今天发布帖子数
			$today_start = strtotime(date('Y-m-d 00:00:00'));
			$today_end = strtotime(date('Y-m-d 23:59:59'));
			
			$count_topic_today = $DB->once_num_rows("select * from ".dbprefix."app_group_topics where groupid='$groupid' and addtime > '$today_start'");
			
			
			$DB->query("update ".dbprefix."app_group set count_topic='$count_topic',count_topic_today='$count_topic_today',uptime='$uptime' where groupid='$groupid'");
			
			
			
			//积分记录
			$userid = $TS_USER['user']['userid'];
			$DB->query("insert into ".dbprefix."app_user_scores (`userid`,`scorename`,`score`,`addtime`) values ('".$userid."','发帖','50','".time()."')");
			
			$strScore = $DB->once_fetch_assoc("select sum(score) score from ".dbprefix."app_user_scores where userid='".$userid."'");
			
			//更新积分
			$DB->query("update ".dbprefix."app_user_info set `count_score`='".$strScore['score']."' where userid='$userid'");
			
			//发帖插件接口
			doAction('topic_add', $title,$topicid,$TS_USER,$TS_SITE,$TS_URL);
			
			header("Location: ".$TS_URL['topic'].$topicid.$TS_URL['suffix']);
			
		}
		break;

	//加入该小组
	case "joingroup":
		
		$userid = intval($TS_USER['user']['userid']);
		
		$groupid = intval($_POST['groupid']);
		
		$groupUserNum = $DB->once_num_rows("select * from ".dbprefix."app_group_users where userid='$userid' and groupid='$groupid'");
		
		if($userid == '0'){
			echo '0';return false;
		}elseif($groupUserNum > 0){
			echo '1';return false;
		}else{
		
			$DB->query("INSERT INTO ".dbprefix."app_group_users (`userid`,`groupid`,`addtime`) VALUES ('".$userid."','".$groupid."','".time()."')");
			
			//计算小组会员数
			$groupUserNum = $DB->once_num_rows("select * from ".dbprefix."app_group_users where groupid='$groupid'");
			//更新小组成员统计
			$DB->query("update ".dbprefix."app_group set `count_user`='$groupUserNum' where groupid='$groupid'");

			echo '2';return false;
		
		}
	
		break;
	
	//退出该小组
	case "exitgroup":
		
		$userid = $TS_USER['user']['userid'];
		$groupid = intval($_POST['groupid']);
		
		//判断是否是组长，是组长不能退出小组
		$strGroup = $DB->once_fetch_assoc("select userid from ".dbprefix."app_group where groupid='$groupid'");
		
		if($userid == $strGroup['userid']){
			echo '0';return false;
		}else{
			$DB->query("DELETE FROM ".dbprefix."app_group_users WHERE userid='$userid' and groupid='$groupid'");
			
			//计算小组会员数
			$groupUserNum = $DB->once_num_rows("select * from ".dbprefix."app_group_users where groupid='$groupid'");
			
			//更新小组统计
			$DB->query("update ".dbprefix."app_group set `count_user`='$groupUserNum' where groupid='$groupid'");
			
			echo '1';return false;
		}
		
		break;
	
	//上传小组头像
	
	case "groupicon":
		
		$groupid = intval($_POST['groupid']);
		
		//处理目录存储方式
		$menu = substr($groupid,0,1);
		
		$uptypes = array( 
			'image/jpg',
			'image/jpeg',
			'image/png',
			'image/pjpeg',
			'image/gif',
			'image/x-png',
		);

		if(isset($_FILES['picfile'])){
		
			$f=$_FILES['picfile'];
			
			if(empty($f['name'])){
			
				qiMsg("头像不能为空！");
				
			}elseif ($f['name']){
				if (!in_array($_FILES['picfile']['type'],$uptypes)) {
					echo "<script>alert(\"提示：你上传的头像图片类型不正确，系统仅支持 jpg,gif,png 格式的图片,点击确认返回！\");window.location.href='set.php?action=face';</script>";
					exit;
				}
			} 		
			
			$dest_dir='data/uploadfile/group/'.$menu.'/'.$groupid;
			
			createFolders($dest_dir);
			
			//原图
			
			$fileInfo=pathinfo($f['name']);
			$extension=$fileInfo['extension'];
			
			$dest=$dest_dir.'/'.mt_rand(10000,99999).'.'.$extension;
			
			$dest98=$dest_dir.'/'.$groupid."_98.".$extension;
			$dest48=$dest_dir.'/'.$groupid."_48.".$extension;
			
			move_uploaded_file($f['tmp_name'],iconv("UTF-8","gb2312",$dest));
			chmod($dest, 0755);
			
			require_once THINKSAAS.'/class.tsImg.php';
			
			$resizeimage = new tsImg("$dest", "98", "98", "1","$dest98");
			$resizeimage = new tsImg("$dest", "48", "48", "1","$dest48");
			
			//删除原图
			unlink("$dest");
			
			//更新小组头像
			$DB->query("update ".dbprefix."app_group set groupicon='$dest48' where groupid='$groupid'");

			header("Location: index.php?app=group&ac=edit_group&groupid=".$groupid."&ts=icon");
			
		}
		
		break;
	
	//编辑小组基本信息
	case "edit_base":
	
		$arrData = array(
			'groupname'	=> t($_POST['groupname']),
			'groupdesc'	=> h($_POST['groupdesc']),
			'joinway'		=> trim($_POST['joinway']),
			'isopen'		=> trim($_POST['isopen']),
			'role_leader'	=> trim($_POST['role_leader']),
			'role_admin'	=> trim($_POST['role_admin']),
			'role_user'	=> trim($_POST['role_user']),
		);
		
		$groupid = intval($_POST['groupid']);
		
		$DB->updateArr($arrData,'app_group','where groupid='.$groupid.'');
		
		//更新所有帖子中对应小组的名称
		$groupname = t($_POST['groupname']);
		$DB->query("update ".dbprefix."app_group_topics set `groupname`='$groupname' where groupid='$groupid'");
		
		header("Location: index.php?app=group&ac=edit_group&groupid=".$groupid."&ts=base");
		
		break;
	
	//添加小组分类索引
	case "addgroupcateindex":
		$groupid = $_POST['groupid'];
		$cateid = $_POST['cateid'];
		
		$uptime = time();
		
		$strCate = $DB->once_fetch_assoc("select catereferid from ".dbprefix."app_group_cates where cateid='$cateid'");
		$catereferid = $strCate['catereferid'];
		
		if($catereferid > 0){
			$DB->query("INSERT INTO ".dbprefix."app_group_cates_index (`groupid`,`cateid`) VALUES ('$groupid','$cateid')");
		
			//更新分类下小组数
			$groupnum = $DB->once_num_rows("select * from ".dbprefix."app_group_cates_index where cateid='$cateid'");
			
			$DB->query("update ".dbprefix."app_group_cates set `count_group`='$groupnum',`uptime`='$uptime' where cateid='$cateid'");
			//统计顶级分类下小组数
			$grouptotal = $DB->once_fetch_assoc("select sum(`count_group`) as `total` from ".dbprefix."app_group_cates where catereferid='$catereferid'");
			
			$total = $grouptotal['total'];
			
			$DB->query("update ".dbprefix."app_group_cates set `count_group`='$total',`uptime`='$uptime' where cateid='$catereferid'");
			
			echo '0';
			
		}else{
			echo '1';
		}

		break;
		
	//将用户全部绑定到群组
	case "groupuser":
		$groupid = $_GET['groupid'];
		
		$arrUser = $DB->fetch_all_assoc("select userid from ".dbprefix."app_user order by userid desc");
		
		foreach($arrUser as $item){
			$groupusernum = $DB->once_num_rows("select * from ".dbprefix."app_group_users where  userid='".$item['userid']."' and groupid='".$groupid."'");
			
			if($groupusernum == '0'){
				$DB->query("insert into ".dbprefix."app_group_users (`userid`,`groupid`,`addtime`) values ('".$item['userid']."','".$groupid."','".time()."')");
				echo $item['userid']."<br />";
			}
			
		}
		
		$userNum = $DB->once_num_rows("select * from ".dbprefix."app_group_users where groupid='".$groupid."'");
		
		$DB->query("update ".dbprefix."app_group set `count_user`='".$userNum."' where groupid='".$groupid."'");
		
		echo $userNum;
		
		break;
	
	//添加话题附件
	case "topic_attach_add":
		
		if($_FILES['attach']['name'][0] == '') qiMsg("上传文件不能为空！");
		
		$groupid = $_POST['groupid'];
		$topicid = $_POST['topicid'];
		
		//处理目录存储方式
		$menu = substr($topicid,0,1);
		
		$date = date('Ymd');
		
		$dest_dir='data/uploadfile/group/topic/'.$menu.'/'.$date.'/'.$topicid;
		createFolders($dest_dir);
	
		$score = intval($_POST['score']);
		$isview = $_POST['isview'];
		
		if(isset($_FILES['attach'])){
			$arrFileName = $_FILES['attach']['name'];
			foreach($arrFileName as $key=>$item){
				if($item != ''){
					$attachname = $item;
					$attachtype = $_FILES['attach']['type'][$key];
					$attachsize = $_FILES['attach']['size'][$key];
					
					$dest=$dest_dir.'/'.$item;
					move_uploaded_file($_FILES['attach']['tmp_name'][$key], iconv("UTF-8","gb2312",$dest));
					chmod($dest, 0755);
					
					$arrData = array(
						'userid'	=> $TS_USER['user']['userid'],
						'groupid'		=> $groupid,
						'topicid'		=> $topicid,
						'attachname'	=> $attachname,
						'attachtype'	=> $attachtype,
						'attachurl'		=> $dest,
						'attachsize'		=> $attachsize,
						'score'		=> $score,
						'isview'		=> $isview,
						'addtime'	=> time(),
					);
					
					$attachid = $DB->insertArr($arrData,'app_group_topics_attachs');
					
				}
				
			}
		}		
		
		//统计附件并更新
		$count_attach = $DB->once_num_rows("select * from ".dbprefix."app_group_topics_attachs where topicid='".$topicid."'");
		$DB->query("update ".dbprefix."app_group_topics set `count_attach`='".$count_attach."' where topicid='".$topicid."'");
		
		header("Location: ".$TS_URL['topic'].$topicid.$TS_URL['suffix']);
		
		break;
	
	//创建小组
	case "group_add":
		
		$userid = intval($TS_USER['user']['userid']);
		
		if($userid=='0' || $_POST['groupname']=='' || $_POST['groupdesc']=='') qiMsg("色即是空，空即是色！");
		
		//配置文件是否需要审核
		$isaudit = intval($TS_APP['options']['isaudit']);
		
		$arrData = array(
			'userid'			=> $userid,
			'groupname'	=> t($_POST['groupname']),
			'groupdesc'		=> h($_POST['groupdesc']),
			'isaudit'	=> $isaudit,
			'addtime'		=> time(),
		);
		
		$groupid = $DB->insertArr($arrData,'app_group');
		
		//绑定成员
		$DB->query("insert into ".dbprefix."app_group_users (`userid`,`groupid`,`addtime`) values ('".$userid."','".$groupid."','".time()."')");
		
		//更新
		$DB->query("update ".dbprefix."app_group set `count_user` = '1' where groupid='".$groupid."'");

		header("Location: index.php?app=group&ac=group&groupid=".$groupid."");
		
		break;
		
	//删除评论回帖
	case "comment_del":
	
		$topicid = intval($_POST['topicid']);
		$commentid = intval($_POST['commentid']);
		
		$DB->query("DELETE FROM ".dbprefix."app_group_topics_comments WHERE commentid = '".$commentid."'");
		
		//统计
		$DB->query("update ".dbprefix."app_group_topics set count_comment=count_comment-1 where topicid='".$topicid."'");
		
		echo '0';
		
		
		break;
		
	//删除帖子
	case "topic_del":
		
		$groupid = $_POST['groupid'];
		$topicid = $_POST['topicid'];
		
		//删除帖子
		$DB->query("DELETE FROM ".dbprefix."app_group_topics WHERE topicid = '".$topicid."'");
		//删除评论回复
		$DB->query("DELETE FROM ".dbprefix."app_group_topics_comments WHERE topicid = '".$topicid."'");
		//删除tag索引
		$DB->query("DELETE FROM ".dbprefix."app_tag_topic_index WHERE topicid = '".$topicid."'");
		
		//统计 
		$DB->query("update ".dbprefix."app_group set count_topic=count_topic-1 where groupid='".$groupid."'");
		
		echo '0';
		
		break;
		
	//编辑帖子 
	case "topic_eidt":
		
		$topicid = $_POST['topicid'];
		$title = t($_POST['title']);
		$typeid = $_POST['typeid'];
		$content = h($_POST['content']);
		
		$iscomment = $_POST['iscomment'];
		
		$userid = intval($TS_USER['user']['userid']);
		
		if($topicid == '' || $title=='' || $content=='') qiMsg("都不能为空的哦!");
		
		$strTopic = $DB->once_fetch_assoc("select * from ".dbprefix."app_group_topics where topicid='".$topicid."'");
		
		$strGroup = $DB->once_fetch_assoc("select userid from ".dbprefix."app_group where groupid='".$strTopic['groupid']."'");
		
		$strGroupUser = $DB->once_fetch_assoc("select * from ".dbprefix."app_group_users where userid='$userid' and groupid='".$strTopic['groupid']."'");
		
		if($TS_USER['user']['userid'] != $strTopic['userid'] && $TS_USER['user']['userid'] != $strGroup['userid'] && $strGroupUser['isadmin'] == '0') qiMsg("机房重地，请勿进入！");
		
		$arrData = array(
			'typeid' => $typeid,
			'title' => $title,
			'content' => $content,
			'iscomment' => $iscomment,
		);
		
		//判断是否有图片和附件
		preg_match_all('/\[(photo)=(\d+)\]/is', $content, $isphoto);
		if($isphoto[2]){
			$arrData['isphoto'] = '1';
		}else{
			$arrData['isphoto'] = '0';
		}
		//判断附件
		preg_match_all('/\[(attach)=(\d+)\]/is', $content, $isattach);
		if($isattach[2]){
			$arrData['isattach'] = '1';
		}else{
			$arrData['isattach'] = '0';
		}
		
		$DB->updateArr($arrData,'app_group_topics','where topicid='.$topicid.'');

		header("Location: ".$TS_URL['topic'].$topicid.$TS_URL['suffix']);
		
		break;
		
	//收藏帖子
	case "topic_collect":
		
		$userid = $TS_USER['user']['userid'];
		$topicid = $_POST['topicid'];
		
		$strTopic = $DB->once_fetch_assoc("select * from ".dbprefix."app_group_topics where topicid='".$topicid."'");
		
		$collectNum = $DB->once_num_rows("select * from ".dbprefix."app_group_topics_collects where userid='$userid' and topicid='$topicid'");
		
		if($userid == ''){
			echo '0';
		}elseif($userid == $strTopic['userid']){
			echo '1';
		}elseif($collectNum > 0){
			echo '2';
		}else{
			$DB->query("insert into ".dbprefix."app_group_topics_collects (`userid`,`topicid`,`addtime`) values ('".$userid."','".$topicid."','".time()."')");
			echo '3';
		}
		
		break;
		
	//置顶帖子
	case "topic_istop":
	
		$topicid = $_POST['topicid'];
		$istop = $_POST['istop'];
		
		$DB->query("update ".dbprefix."app_group_topics set istop='$istop' where topicid='$topicid'");
		
		echo '0';
		
		break;
		
	//隐藏显示帖子
	case "topic_isshow":
	
		$topicid = $_POST['topicid'];
		$isshow = $_POST['isshow'];
		
		$DB->query("update ".dbprefix."app_group_topics set isshow='$isshow' where topicid='$topicid'");
		
		echo '0';
		
		break;
	
	//帖子标签
	case "topic_tag_ajax";
		
		$topicid = $_GET['topicid'];
		include TmooTemplate("topic_tag_ajax");
		break;
	
	//添加帖子标签
	case "topic_tag_do":
		
		$topicid = $_POST['topicid'];
		$tagname = t($_POST['tagname']);
		$uptime	= time();
		
		if($tagname != ''){
		
			if(strlen($tagname) > '32') qiMsg("标题长度大于32个字节（不能超过16个汉字）");
			
			$tagcount = $DB->once_num_rows("select * from ".dbprefix."app_tag where tagname='".$tagname."'");
			
			if($tagcount == '0'){
				$DB->query("INSERT INTO ".dbprefix."app_tag (`tagname`,`uptime`) VALUES ('".$tagname."','".$uptime."')");
				$tagid = $DB->insert_id();
				
				$tagIndexCount = $DB->once_num_rows("select * from ".dbprefix."app_tag_topic_index where topicid='".$topicid."' and tagid='".$tagid."'");
				if($tagIndexCount == '0'){
					$DB->query("INSERT INTO ".dbprefix."app_tag_topic_index (`topicid`,`tagid`) VALUES ('".$topicid."','".$tagid."')");
				}
				
				$tagIdCount = $DB->once_num_rows("select * from ".dbprefix."app_tag_topic_index where tagid='".$tagid."'");
				
				$DB->query("update ".dbprefix."app_tag set `count_topic`='".$tagIdCount."',`uptime`='".$uptime."' where tagid='".$tagid."'");
				
			}else{
				
				$tagData = $DB->once_fetch_assoc("select * from ".dbprefix."app_tag where tagname='".$tagname."'");
				
				$tagIndexCount = $DB->once_num_rows("select * from ".dbprefix."app_tag_topic_index where topicid='".$topicid."' and tagid='".$tagData['tagid']."'");
				if($tagIndexCount == '0'){
					$DB->query("INSERT INTO ".dbprefix."app_tag_topic_index (`topicid`,`tagid`) VALUES ('".$topicid."','".$tagData['tagid']."')");
				}
				
				$tagIdCount = $DB->once_num_rows("select * from ".dbprefix."app_tag_topic_index where tagid='".$tagData['tagid']."'");
				
				$DB->query("update ".dbprefix."app_tag set `count_topic`='".$tagIdCount."',`uptime`='".$uptime."' where tagid='".$tagData['tagid']."'");
				
			}
			
			echo "<script language=JavaScript>parent.window.location.reload();</script>";
			
		}
		
		break;
		
	//帖子分类
	case "topic_type":
	
		$groupid = intval($_POST['groupid']);
		$typename = trim($_POST['typename']);
		$DB->query("insert into ".dbprefix."app_group_topics_type (`groupid`,`typename`) values ('$groupid','$typename')");
		
		header("Location: index.php?app=group&ac=edit_group&ts=type&groupid=".$groupid);
		
		break;
			
	//回复评论
	case "recomment":
		$userid = $TS_USER['user']['userid'];
		$referid = $_POST['referid'];
		$topicid = $_POST['topicid'];
		$content = trim($_POST['content']);
		$addtime = time();
		
		$DB->query("insert into ".dbprefix."app_group_topics_comments (`referid`,`topicid`,`userid`,`content`,`addtime`) values ('$referid','$topicid','$userid','$content','$addtime')");
		
		//统计评论数
		$count_comment = $DB->once_num_rows("select * from ".dbprefix."app_group_topics_comments where topicid='$topicid'");
		
		//更新帖子最后回应时间和评论数
		$uptime = time();
		
		$DB->query("update ".dbprefix."app_group_topics set uptime='$uptime',count_comment='$count_comment' where topicid='$topicid'");
		
		$strTopic = $DB->once_fetch_assoc("select * from ".dbprefix."app_group_topics where topicid='$topicid'");
		$strComment = $DB->once_fetch_assoc("select * from ".dbprefix."app_group_topics_comments where commentid='$referid'");
		
		if($topicid && $strTopic['userid'] != $TS_USER['user']['userid']){
			$msg_userid = '0';
			$msg_touserid = $strTopic['userid'];
			$msg_content = '你的帖子：《'.$strTopic['title'].'》新增一条评论，快去看看给个回复吧^_^ <br />'.$TS_SITE['base']['site_url'].'index.php?app=group&ac=topic&topicid='.$topicid;
			aac('message',$DB)->sendmsg($msg_userid,$msg_touserid,$msg_content);
		}
		
		if($referid && $strComment['userid'] != $TS_USER['user']['userid']){
			$msg_userid = '0';
			$msg_touserid = $strComment['userid'];
			$msg_content = '有人评论了你在帖子：《'.$strTopic['title'].'》中的回复，快去看看给个回复吧^_^ <br />'.$TS_SITE['base']['site_url'].'index.php?app=group&ac=topic&topicid='.$topicid;
			aac('message',$DB)->sendmsg($msg_userid,$msg_touserid,$msg_content);
		}
		
		echo '0';
		
		break;
	
	//编辑帖子类型
	case "edit_type":
		$typeid = $_POST['id'];
		$typename = t($_POST['value']);
		if(empty($typename)){
			echo '帖子类型不能为空，请点击继续编辑';
		}else{
			$DB->query("update ".dbprefix."app_group_topics_type set `typename`='$typename' where typeid='$typeid'");
			echo $typename;
		}
		break;
	//删除帖子类型 
	case "del_type":
		$typeid = $_POST['typeid'];
		$DB->query("delete from ".dbprefix."app_group_topics_type where typeid='$typeid'");
		$DB->query("update ".dbprefix."app_group_topics set typeid='0' where typeid='$typeid'");
		echo '0';
		break;
		
	//取消小组分类
	case "cate_cancel":
		$cateid = $_POST['cateid'];
		$groupid = $_POST['groupid'];
		$DB->query("delete from ".dbprefix."app_group_cates_index where groupid='$groupid' and cateid='$cateid'");
		echo '0';
		break;
			
	//计算帖子中是否有图片
	case "isphoto":
		$arrTopic = $DB->fetch_all_assoc("select * from ".dbprefix."app_group_topics");
		foreach($arrTopic as $item){
			$content = $item['content'];
			$topicid = $item['topicid'];
			preg_match_all('/\[(photo)=(\d+)\]/is', $content, $photo);
			if($photo[2]){
				$DB->query("update ".dbprefix."app_group_topics set `isphoto`='1' where topicid='$topicid'");
				echo '==OK==';
			}
		}
		break;
		
}